package com.spring.demo.untils.parse.blood;

import com.spring.demo.untils.dto.OpenRes;
import com.spring.demo.untils.dto.Result;
import com.spring.demo.untils.dto.request.HisBloodApplyRequest;
import com.spring.demo.untils.parse.ResponseParse;

import java.util.*;

/**
 * @author xuweizhi
 * @since 2023/07/06 17:46
 */
public class CreateDoctorOrderResponseParse implements ResponseParse<HisBloodApplyRequest> {


    @Override
    public boolean matchParse(String suffixUrl, Long routerId) {
        return Objects.equals(suffixUrl, "/gw-api/hbos-thirdparty-integration/standard/bimis/apply/createDoctorOrder") || Objects.equals(routerId, 10018009L);
    }

    @Override
    public HisBloodApplyRequest parseRequestBody(OpenRes openRes) {
        Result<String> resResult = this.parseResponseBody(openRes);
        if (Objects.equals(resResult.getCode(), 200)) {
            return null;
        }
        OpenRes.OriginRequestDTO originRequest = openRes.getOriginRequest();
        return GSON.fromJson(originRequest.getBody(), HisBloodApplyRequest.class);
    }

    @Override
    public void execute(List<HisBloodApplyRequest> data) {
        Map<String, HisBloodApplyRequest> xx = new HashMap<>();
        for (HisBloodApplyRequest hisBloodBagStatusRequest : data) {
            xx.put(hisBloodBagStatusRequest.getDoctorOrderNo(), hisBloodBagStatusRequest);
        }
        xx.values().stream().sorted(Comparator.comparing(HisBloodApplyRequest::getStartTime)).forEach(hisBloodBagStatusRequest -> System.out.println(hisBloodBagStatusRequest.getDoctorOrderNo()));
    }


}
